package controller.core;

import pojo.account.Reader;
import service.CoreService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.Timestamp;

@WebServlet(name = "ReserveController", value = "/ReserveController")
public class ReserveController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Reader reader = (Reader) request.getSession().getAttribute("reader");
        String floorName = request.getParameter("floorName");
        int number = Integer.parseInt(request.getParameter("number"));

        // reserve the seat(floorName,number)
        Timestamp reserveTime = new CoreService().reserve(reader.getId(), floorName, number);
        request.setAttribute("reserveTime", reserveTime);

        request.getRequestDispatcher("/RGetRecordController").forward(request, response);
    }
}
